﻿CREATE FUNCTION [acms].[GetPublishDate]
(
	@SiteVersion DateTime
)
RETURNS DateTime
AS
BEGIN
	declare @tmp DateTime
	if(@SiteVersion is not null) begin
		set @SiteVersion = DateAdd(n, 1, @SiteVersion)
		select top 1 @tmp = PublishDate from PostPositions where PublishDate <= @SiteVersion order by PublishDate desc
	end
	return @tmp
END